#-*- codeing = utf-8 -*-
#@Time : 2020/9/9 20:13
#@Author : 阳某
#@File : testre.py
#@Software : PyCharm

import requests
from urllib.parse import quote
if __name__ == '__main__':
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3775.400 QQBrowser/10.6.4208.400'
    }
    wd = quote(input("请输入关键字："))
    print(wd)
    # https://www.baidu.com/s?wd=%E6%B3%A2%E6%99%93%E5%BC%A0    #百度搜索
    # https://www.sogou.com/tx?&query=波晓张       #搜狗搜索
    url = 'https://www.baidu.com/s'
    param = {
        'wd': wd
    }
    response = requests.get(url, params=param, headers=headers)
    print(response.status_code)
    print(response.text)
    filename = wd + '.html'
    with open(filename, 'w', encoding='utf-8') as f:
        f.write(response.text)
    print(filename, '保存成功！！！')







    '''headers = {
        'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3775.400 QQBrowser/10.6.4208.400'
    }
    wd = input("请输入关键字：")
    # https://www.baidu.com/s?wd=%E6%B3%A2%E6%99%93%E5%BC%A0    #百度搜索
    # https://www.sogou.com/tx?&query=波晓张       #搜狗搜索
    url = 'https://www.sogou.com/tx'
    param = {
        'query':wd
    }
    response = requests.get(url,params = param,headers = headers)
    print(response.status_code)
    # print(response.text)
    filename = wd+'.html'
    with open(filename,'w',encoding='utf-8') as f:
        f.write(response.text)
    print(filename,'保存成功！！！')'''